<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta content="width=device-width, initial-scale=1" name="viewport">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>webrx</title>
    <?php
    $bgc = "#fff";
    if (isset($_COOKIE['bgc'])) {
        $bgc = $_COOKIE['bgc'];
    }
    ?>

    <style>
        button {
            padding: 5px;
            margin: 2px;
            border: 2px dashed transparent;
            cursor: pointer;
            color: #fffa;
            border-radius: 2px;
        }

        button:hover {
            opacity: .8;
        }

        body {
            background-color: <?=$bgc?>;
        }
    </style>

</head>
<body>
<?php

function randcolor() {
    $cs = '0123456789abcdef';
    $cc = '#';
    for ($i = 0; $i < 6; $i++) {
        $cc .= $cs[rand(0, strlen($cs) - 1)];
    }
    return $cc;
}

function setColor($c) {
    setcookie('bgc', $c, time() + (3600 * 24));
    return $c;
}

?>

<?php
for ($i = 0; $i <= 30; $i++) {
    $c = randcolor();
    ?>
    <button style="background-color:<?= $c ?>" onclick="body.style.backgroundColor=this.style.backgroundColor"><?= $c ?></button>
    <?php
}
?>

</body>
</html>
